package com.jason.mvptest3;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.jason.mvptest3.bean.Person;
import com.jason.mvptest3.itfcontract.LoginContract;
import com.jason.mvptest3.presenter.LoginPresenter;

public class MainActivity extends AppCompatActivity implements LoginContract.View {

    private LoginPresenter mLoginPresenter;
    private EditText et_username;
    private EditText et_password;
    private Button bt_login;
    private ProgressDialog mDialog;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mLoginPresenter = new LoginPresenter(this);
        et_username = (EditText) findViewById(R.id.et_username);
        et_password = (EditText) findViewById(R.id.et_password);
        bt_login = (Button) findViewById(R.id.bt_login);
        mDialog = new ProgressDialog(this);
        mDialog.setMessage("正在登陆.....");
        bt_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mLoginPresenter.loadingTask();

            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    public void showLoadingDialog() {
        if (!mDialog.isShowing()) {
            mDialog.show();
        }
    }

    @Override
    public void hideLoadingDialog() {

        if (mDialog.isShowing()) {
            mDialog.dismiss();
        }

    }

    @Override
    public String getUserName() {
        return et_username.getText().toString().trim();
    }

    @Override
    public String getPassWord() {
        return et_password.getText().toString().trim();
    }

    @Override
    public void showLoadingError(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void cleanUserName() {

    }

    @Override
    public void cleanPassWord() {

    }

    @Override
    public void toActivity(Person person) {
        Toast.makeText(this, person.getUsername() + ",恭喜你登陆成功", Toast.LENGTH_SHORT).show();
    }


    @Override
    public void showUserNameOrPassWordEmpty() {
        Toast.makeText(this, "用户名或密码请填写完整", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void setPersenter(LoginContract.Presenter persenter) {

    }
}
